package com.tiankong.product.controller;


import com.tiankong.product.entity.Brand;
import com.tiankong.product.entity.CategoryBrand;
import com.tiankong.product.service.CategoryBrandRelationService;
import net.youdi.common.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 品牌分类关联 前端控制器
 * </p>
 *
 * @author scl
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/categorybrandrelation")
public class CategoryBrandRelationController {

    @Autowired
    private CategoryBrandRelationService relationService;

    @GetMapping("catelog/list/{brandId}")
    public Result catelogList(@PathVariable("brandId")  Long brandId){
        List<CategoryBrand> list = relationService.listByBrandId(brandId);
        return Result.ok(list);
    }
    @PostMapping("save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        relationService.saveRelation(categoryBrand);
        return Result.ok(categoryBrand);
    }
    @DeleteMapping("delete/{brandId}/{catelogId}")
    public Result delete(@PathVariable("brandId")  Long brandId,@PathVariable("catelogId")  Long catelogId){
        relationService.update().eq("brand_id",brandId).eq("catelog_id",catelogId).remove();
        return Result.ok();
    }

    /**
     * 分类关联的品牌列表
     * @param catId
     * @return
     */
    @GetMapping("brands/list/{catId}")
    public Result brands(@PathVariable("catId")  Long catId){
        List<CategoryBrand> list = relationService.listBrandByCatId(catId);
        return Result.ok(list);
    }
}
